extends Node2D

@onready var animation_player: AnimationPlayer = %AnimationPlayer
## 被创作者
var creater
var weapon_damage: float = 1.0

func _ready() -> void:
	look_at(get_global_mouse_position())
	animation_player.play("attack")

func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if anim_name == "attack":
		queue_free()

func _on_area_2d_area_entered(enemy: Area2D) -> void:
	var is_critical = false
	var final_damage = weapon_damage + Utils.get_player_stats_value("base_damage") + Utils.get_player_stats_value("additional_damage")
	var stealth_damage_multiplier = Utils.get_player_stats_value("stealth_damage_multiplier")
	if Utils.player.buff_manager.has_buff("燃烧的蜡烛"):
		if randf() < 0.2:
			Utils.show_fluent_tip("燃烧的蜡烛触发")
			final_damage *= 3
			is_critical = true
				
		# 检查玩家暴击率
	var crit_chance = Utils.get_player_stats_value("critical_chance")
	var crit_multiplier = Utils.get_player_stats_value("critical_multiplier")
	if crit_chance > 0 and randf() * 100 < crit_chance:
		is_critical = true
		final_damage *= crit_multiplier

	# 检查是否有隐身伤害倍数	
	if stealth_damage_multiplier > 0:
		is_critical = true
		final_damage *= stealth_damage_multiplier
		# 移除伤害倍数（一次性使用）
		Utils.set_player_stats_value("stealth_damage_multiplier", -stealth_damage_multiplier)
		Utils.show_string_label_c("隐身攻击！", Utils.player, Color.PURPLE)
		Utils.player.buff_manager.remove_buff("隐身")
	enemy.enemy_hurt(self, final_damage, is_critical)
	## 触发玩家攻击效果
	EventBus.push_event("player_attack_effect", [])
